import 'package:flutter/material.dart';
import 'package:p_location/common/ui/base_list_page.dart';
import 'package:p_location/common/widget/common_app_bar.dart';
import 'package:p_location/common/widget/fix_tab_bar_view.dart';

abstract class BaseTabPage<T> extends StatefulWidget {
  BaseTabPageState getState();

  @override
  BaseTabPageState createState() => getState();
}

abstract class BaseTabPageState<T extends BaseTabPage> extends State<T>
    with SingleTickerProviderStateMixin {
  PageController _pageController;
  TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: getTabTiles().length, vsync: this);
    _pageController = PageController();
  }

  @override
  void dispose() {
    super.dispose();
    _tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonAppBar(
        title: Text(
          getTitle(),
          style: TextStyle(color: Colors.black),
        ),
        onPress: () {
          Navigator.of(context).pop();
        },
      ),
      body: Column(
        children: <Widget>[
          TabBar(
            labelColor: Colors.blue,
            controller: _tabController,
            tabs: getTabTiles(),
            onTap: (index) {
              _pageController.jumpToPage(index);
            },
          ),
          Expanded(
            child: FixTabBarView(
                pageController: _pageController,
                tabController: _tabController,
                children: getTabItemPage()),
          ),
        ],
      ),
    );
  }

  String getTitle();

  List<Tab> getTabTiles();

  List<BaseListPage> getTabItemPage();
}
